package com.ruoyi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.ProductAttribute;
import com.ruoyi.business.service.IProductAttributeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.ApiOperation;

/**
 * 商品属性Controller
 * 
 * @author ruoyi
 * @date 2025-03-13
 */
@Api(tags = "商品属性管理")  // 补充完整Swagger标签
@RestController
@RequestMapping("/business/attribute/product")
public class ProductAttributeController extends BaseController {
    @Autowired
    private IProductAttributeService productAttributeService;

    /**
     * 查询商品属性列表
     */
    @ApiOperation("属性列表")
    @PreAuthorize("@ss.hasPermi('business:attribute:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductAttribute productAttribute) {
        startPage();
        List<ProductAttribute> list = productAttributeService.selectProductAttributeList(productAttribute);
        return getDataTable(list);
    }

    /**
     * 获取商品属性详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:attribute:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(productAttributeService.selectProductAttributeById(id));
    }

    /**
     * 新增商品属性
     */
    @ApiOperation("新增属性")
    @PreAuthorize("@ss.hasPermi('business:attribute:add')")
    @Log(title = "商品属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody ProductAttribute productAttribute) {
        productAttribute.setCreateBy(getUsername());
        return toAjax(productAttributeService.insertProductAttribute(productAttribute));
    }

    /**
     * 修改商品属性
     */
    @ApiOperation("修改属性")
    @PreAuthorize("@ss.hasPermi('business:attribute:edit')")
    @Log(title = "商品属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody ProductAttribute productAttribute) {
        productAttribute.setUpdateBy(getUsername());
        return toAjax(productAttributeService.updateProductAttribute(productAttribute));
    }

    /**
     * 删除商品属性
     */
    @ApiOperation("删除属性")
    @PreAuthorize("@ss.hasPermi('business:attribute:remove')")
    @Log(title = "商品属性", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(productAttributeService.deleteProductAttributeByIds(ids));
    }
}
